package cn.toutatis.sandbox.root.systemService.mapper;


import cn.toutatis.sandbox.root.systemService.entity.SystemDictionary;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* <p>
    * 静态字典 Mapper 接口
    * </p>
*
* @author Toutatis_Gc
* @since 2020-07-09
*/
@Mapper
@Repository
public interface SystemDictionaryMapper extends BaseMapper<SystemDictionary> {
    /**
     * @param val 静态字典code码
     * @return 该code下所有字典值
     */
    @Select("SELECT * FROM system_dictionary a, (SELECT * FROM system_dictionary WHERE `code` = #{val} LIMIT 1) b WHERE a.parentId = b.id")
    List<SystemDictionary> staticDic(@Param("val") Object val);

    /**
     * @param id 查询字典本身和是否有下级
     * @return 带有hasChild的字典列表
     */
    @Select("SELECT a.*,(SELECT COUNT(1) FROM system_dictionary b WHERE parentId = a.id ) childCount FROM system_dictionary a WHERE parentId = #{id} AND status = 'SYS_OPEN_0000' limit #{currentPage},#{pageSize}")
    List<SystemDictionary> getTree(@Param("id") Object id,@Param("currentPage") int currentPage,@Param("pageSize") int pageSize);
}
